<h2 style='text-align:center'>征候编辑</h2>

<div style='margin-bottom:20px'>
	<button id='main_type2_viewAdd'>添加症状</button>
	
	<div id='main_type2_addArea' style='display:none;position:fixed;border:0px solid;left:0;top:0;width:100%;height:100%;overflow-y:scroll'>
		<div style='margin:50px auto;border:1px solid;width:80%;background:#ccc;padding:5px'>
		
			<div id='main_type2_viewZhengZhuangList'>
				<h3>分类名</h3>
				<div style='margin-left:20px;word-break:break-all'>
					<label><input type="checkbox" name='list[]' value='aa' />aa</label>
				</div>
			</div>
		
			<div style='text-align:center;margin:30px'>
				<button id='main_type2_AddBtn'>提交</button>
				<button id='main_type2_CancelBtn'>取消</button>
			</div>
		</div>
	</div>
</div>



<div>
	<div style='font:normal bold 18px/40px Georgia'>
		<span id='zhengHouName'>征候名：</span>
		<span style='margin-left:30px'>
			<button id='main_type2_viewRname'>重命名</button>
			<span id='main_type2_rnameArea' style='display:none'>
				<input type="text" placeholder='输入症状名' id='main_type2_rnameInp' />
				<button id='main_type2_rnameAddBtn'>提交</button>
				<button id='main_type2_rnameAddCancel'>取消</button>
			</span>
		  　<button id='main_type2_delTypeName'>删除征候</button>
	  	</span>
	 </div>
	<div style='margin-left:40px;word-break:break-all' id='main_type2_zhengHouSubList'>
		<!--div style='margin:10px 0'>
			<span>症状1</span>
			<span style='margin-left:10px'>删除</span>
		</div-->
	</div>
</div>

<div style='text-align:center;margin:30px'><button onclick='_main_type2_back()'>返回</button></div>


<script>
//C(zhengHouData[tmp_index]);


//显示当前征候名
$('#zhengHouName').text(zhengHouData[tmp_index].name);

//显示症状列表
if(zhengHouData[tmp_index].subList && zhengHouData[tmp_index].subList.length > 0){
	var subList = zhengHouData[tmp_index].subList;
	var tmp_str = '';
	for(var i=0;i<subList.length;i++){
		tmp_str += "<div style='margin:10px 0'>";
			tmp_str += "<span>"+subList[i].name+"</span>";
			tmp_str += "<button style='margin-left:50px' onclick=_main_type2_zhengHouDelZhengZhuang("+subList[i].id+") >删除</button>";
		tmp_str += "</div>";
	}
	$('#main_type2_zhengHouSubList').html(tmp_str);
}

//删除征候下的症状
function _main_type2_zhengHouDelZhengZhuang(id){
	if(_confirm() == 'err'){
		return;
	}
	Notice2(1);
	var data = {
		type:'delZhengHouSubZhengZhuang',
		id:id,
		hid:zhengHouData[tmp_index].id //征候id
	}
	Ajax2(data,function(res){
		Notice2();
		if(res.stat == 'ok'){
			A('操作成功！');
			_resetNewData();	//刷新数据并加载到编辑页
		}else{
			A('操作失败！');
		}
	});
}



//添加症状相关
$("#main_type2_viewAdd").click(function(){
	$(this).hide();
	$('#main_type2_addArea').show();

	//获取症状集合	fun.js
	_getClassList(function(res){
		if(res.data.length > 0){
			//解析症状集合	fun.js
			var l1 = res.data;
			var tmp_str = '';
			for(var i=0;i<l1.length;i++){
				tmp_str += "<h3>"+l1[i].name+"</h3>";
				tmp_str += "<div style='margin-left:20px;word-break:break-all'>";
				if(l1[i].subList.length > 0){
					for(var j=0;j<l1[i].subList.length;j++){
						tmp_str += "<label style='margin-right:15px'><input type='checkbox' value="+l1[i].subList[j].id+" />"+l1[i].subList[j].name+"</label>";
					}
				}
				tmp_str += "</div>";
			}
			$('#main_type2_viewZhengZhuangList').html(tmp_str);
		}
	});
});

//给征候添加症状提交
$('#main_type2_AddBtn').click(function(){
	var list = [];
    $.each($('input:checkbox:checked'),function(){
        list.push($(this).val());
    });
    if(list.length < 1){
    	A('选择不得为空！');
    	return;
    }
    Notice2(1);
    var data = {
    	type:'zhengHouAddZhengZhuang',
    	id:zhengHouData[tmp_index].id,
    	list:list.toString()
    }
    Ajax2(data,function(res){
    	Notice2();
    	if(res.stat == 'ok'){
    		//A('操作成功！');
    		_resetNewData();	//刷新数据并加载到编辑页
    	}else{
    		A('操作异常！');
    	}
    })
});
$('#main_type2_CancelBtn').click(function(){
	_main_type2_addAreaInit();
});
function _main_type2_addAreaInit(){
	$('#main_type2_viewAdd').show();
	$('#main_type2_addArea').hide();
}

//刷新数据并加载到编辑页
function _resetNewData(){
	_zhengHou_init();
	setTimeout(function(){
		_type2_loadEditPage(tmp_index);
	},500);
}


//删除征候
$('#main_type2_delTypeName').click(function(){
	if(JSON.parse(zhengHouData[tmp_index].list).length >= 1){
		A('征候下症状不为空！');return;
	}
	if(_confirm() == 'err'){
		return;
	}
	Notice2(1);
	var data = {
		type:'zhengHouDel',
		id:zhengHouData[tmp_index].id
	}
	Ajax2(data,function(res){
		Notice2();
		if(res.stat == 'ok'){
			A('操作成功！');
			zhengHouData.splice(tmp_index,1);
			_parseData(zhengHouData);	//重新解析征候数据
			_main_type2_back();
		}else{
			A('操作失败！');
		}
	})
});



//重命名相关
$('#main_type2_rnameAddBtn').click(function(){
	var name = $('#main_type2_rnameInp').val().trim();
	if(!name){
		return;
	}
	Notice2(1);
	var data = {
		type:'zhengHouRname',
		id:zhengHouData[tmp_index].id,
		name:name
	}
	Ajax2(data,function(res){
		Notice2();
		if(res.stat == 'ok'){
			A('操作成功！');
			zhengHouData[tmp_index].name = name;
			_type2_loadEditPage(tmp_index);
		}else{
			A('操作失败！');
		}
	})
});
$("#main_type2_viewRname").click(function(){
	$(this).hide();
	$('#main_type2_delTypeName').hide();
	$('#main_type2_rnameArea').show();
});
$('#main_type2_rnameAddCancel').click(function(){
	_main_type2_rnameAreaInit();
});
function _main_type2_rnameAreaInit(){
	$('#main_type2_viewRname,#main_type2_delTypeName').show();
	$('#main_type2_rnameArea').hide();
	$('#main_type2_rnameInp').val('');
}






//返回上一级
function _main_type2_back(){
	$('#type2_area1').show();
	$('#type2_area2').hide();
}



</script>